home *** CD-ROM | disk | FTP | other *** search
-
- PEEKs, POKEs, and SYSes -- Part 16
-
- by Jimmy Weiler
-
- ======================================
- Location:631-640 Hexadecimal:$0277-280
- Official Label: KEYD Type: RAM
- Useful BASIC commands: PEEK, POKE
- ======================================
-
- KEYD is the keyboard data buffer.
-
- When a key is pressed, the ASCII value
-
- for that key is stored in 631 + peek
-
- (198) and location 198 is incremented.
-
- What this means without the
-
- gobbledy-gook is that what you type
-
- goes into 631 to 640 in the order you
-
- type it and 198 counts the keystrokes.
-
- To see how it works, try something
-
- like this:
-
- 5 PRINT "DON'T YOU DARE TOUCH DEL!"
- 10 FOR C = 631 TO 640
- 20 PRINT CHR$(PEEK(C));
- 30 NEXT
- 40 ?" ";PEEK(198)
- 50 IF PEEK(198)>6 THEN GET K$
- 60 GOTO 10
-
- You will see the characters you type
-
- filling the buffer. Every time you
-
- GET a character, everything in the
-
- buffer will shift left one, and the
-
- character that has been in the buffer
-
- the longest will be taken out. This
-
- is called a First in-First out (FIFO)
-
- buffer.
-
- But you don't have to be satisfied
-
- with peeking values out of the buffer.
-
- You can poke letters into the buffer
-
- and those letters will be processed as
-
- input from the keyboard. LOADSTAR
-
- uses this technique to connect all the
-
- programs together. Look at our code
-
- to see how we clear the screen, print
-
- commands on it, and then poke enough
-
- carriage returns into the KEYD buffer
-
- to execute the commands on the screen.
-
- Here's a trivial example showing
-
- what can be done by poking KEYD.
-
- 10 C$="RUN ":rem command
- 20 FOR C = 1 TO 10
- 30 POKE C + 630, ASC(MID$(C$,C))
- 40 NEXT C :rem put command in buffer
- 50 POKE 640,13:rem c/r at end of buf
- 60 POKE 198,10:rem 10 chars in buffer
- 70 PRINT "I just ran again."
-
- Every time the program ends it re-
-
- runs itself.
-
- --------------------------------------
-